package com.ux.iot.jetlinks.runner;

import cn.hutool.core.util.ObjectUtil;
import com.ux.iot.jetlinks.service.websocket.SampleJetlinksWebosocketClient;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;

@Slf4j
@AllArgsConstructor
public class JetLinksWebosocketClientRunner implements ApplicationRunner {
    SampleJetlinksWebosocketClient sampleAmqpClient;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        if(ObjectUtil.isNotEmpty(sampleAmqpClient)){
            log.debug("连接jetlinks {}",sampleAmqpClient);
            sampleAmqpClient.getEndpoint().setCloseEvent(()->{
                sampleAmqpClient.start();
                return 1;
            });
            sampleAmqpClient.start();
        }

    }

}
